package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping
    public User getOne(@RequestParam("id") Integer id){
        User user = new User();
        user.setId(id);
        user.setName("zs:"+id);
        return user;
    }

    @PostMapping("/login")
    //这样接收前台参数时，前台传递参数的方式必须是 key=value&key2=value2...
    public String login(User user){
        if ("zhangsan".equals(user.getName())&& "123".equals(user.getPassword())){
            return "登录成功";
        }

        return "登录失败";
    }

    @PostMapping("/login2")
    //这样接收前台参数时，前台传递参数的方式必须是请求体中携带json格式数据
    public String login2(@RequestBody User user){
        if ("zhangsan".equals(user.getName())&& "123".equals(user.getPassword())){
            return "登录成功";
        }

        return "登录失败";
    }

    @PostMapping("/axios")
    public String axios(User paramUser,@RequestBody User dataUser,@RequestHeader("myheader") String header){
        System.out.println("params:" + paramUser);
        System.out.println("data:" + dataUser);
        System.out.println("header:" + header);
        return "success";
    }
}
